package com.pdg.mcplugin.misterdevtool;

import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

import com.pdg.mcplugin.common.baseclasses.PluginClientBase;

public class PlayerInteractEventSpy extends PluginClientBase<MisterDevtool> implements Listener{
	private static final String TAG = "(PIESPY) ";
	private static final String NULL_ACTION = TAG+"Action: NULL";
	private static final String NULL_BLOCK = TAG+"Block: NULL";
	private static final String NULL_ITEMSTACK = TAG+"Item: NULL";
	private static final String NULL_BLOCKFACE = TAG+"BlockFace: NULL";
	private static final String FORMAT_ACTION = TAG+"Action: %s";
	private static final String FORMAT_BLOCKFACE = TAG+"BlockFace: %s";
	private static final String FORMAT_BLOCK = TAG+"Block: %s";
	private static final String FORMAT_ITEM = TAG+"Item: %s";
	private static final String END = TAG+"<end>";
	private static final String START = TAG+"<start>";
	public PlayerInteractEventSpy(MisterDevtool thePlugin) {
		super(thePlugin);
	}
	@EventHandler
	public void onPlayerInteract(PlayerInteractEvent event){
		if(!getPlugin().getFeatureManager().getFeature(MDTFeatures.PIESPY)) return;
		Player thePlayer = event.getPlayer();
		Action theAction = event.getAction();
		Block theBlock = event.getClickedBlock();
		BlockFace theBlockFace = event.getBlockFace();
		ItemStack theItemStack = event.getItem();
		getPlugin().sendInformationalMessage(thePlayer, START);
		if(theAction!=null){
			getPlugin().sendInformationalMessage(thePlayer, String.format(FORMAT_ACTION,theAction.toString()));
		}else{
			getPlugin().sendInformationalMessage(thePlayer, NULL_ACTION);
		}
		if(theBlock!=null){
			getPlugin().sendInformationalMessage(thePlayer, String.format(FORMAT_BLOCK,theBlock.toString()));
		}else{
			getPlugin().sendInformationalMessage(thePlayer, NULL_BLOCK);
		}
		if(theBlockFace!=null){
			getPlugin().sendInformationalMessage(thePlayer, String.format(FORMAT_BLOCKFACE,theBlockFace.toString()));
		}else{
			getPlugin().sendInformationalMessage(thePlayer, NULL_BLOCKFACE);
		}
		if(theItemStack!=null){
			getPlugin().sendInformationalMessage(thePlayer, String.format(FORMAT_ITEM,theItemStack.toString()));
		}else{
			getPlugin().sendInformationalMessage(thePlayer, NULL_ITEMSTACK);
		}
		getPlugin().sendInformationalMessage(thePlayer, END);
	}

}
